package com.iss.controller.user;

import com.google.gson.Gson;
import com.iss.model.ResponseMessage;
import com.iss.model.User;
import com.iss.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/user/login")
public class LoginServlet extends HttpServlet {

    private UserService service = new UserService();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        User user = new User();

        user.setUsername(username);
        user.setPassword(password);

        ResponseMessage repsMsg = service.login(user);

        Gson gson = new Gson();

        response.getWriter().println(gson.toJson(repsMsg));
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
